const path = require("path");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const TerserPlugin = require("terser-webpack-plugin");
const appConfig = require("../app.config.js");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");

module.exports = merge(common, {
  mode: "production",
  entry: {
    index: path.resolve(__dirname, "../src/index.ts"),
  },
  output: {
    path: path.resolve(__dirname, `../build/${appConfig.APP_NAME}`),
  },
  plugins: [
    process.env.ANALYZER &&
      new BundleAnalyzerPlugin({ analyzerPort: appConfig.ANALYZER_PORT }),
  ],
  optimization: {
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          compress: {
            drop_console: true, // 删除所有的 `console` 语句
          },
        },
      }),
    ],
  },
});
